import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'home_logic.dart';


class HomePage extends GetView<HomeLogic> {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    final logic = controller;
    final state = controller.state;
    return Scaffold(
      appBar: AppBar(title: const Text('HomePage')),
      body: Column(children: [
        // Text(logic.state.userinfo.value!.name),
        // ObxValue((data){
        //  return   Text(data.value!.age.toString());
        // }, logic.state.userinfo),
        TextButton(
            onPressed: () {
              state.userModel.name += '1';
            },
            child: Text('${state.userModel.toJson()}')
        ),
        ObxValue((data) {
          return TextButton(
              onPressed: () {
                data.value.name += '1';
                data.refresh();
              },
              child: Text('${data.toJson()}'));
        }, state.userModel2),
        ObxValue((data) {
          return TextButton(
              onPressed: () {
                data.value.name += '1';
                data.refresh();
              },
              child: Text('${data.toJson()}'));
        }, state.userModel3),
        ObxValue((data) {
          return TextButton(
              onPressed: () {
                data.value += '1';
              },
              child: Text('${data}'));
        }, state.name),
        ElevatedButton(
          onPressed: () {
            // print('JtTag:testName:${GetInstance()}');
            // print('JtTag:GetInstance:${GetInstance().hashCode}');
            // print('JtTag:Get:${Get.hashCode}');
            // print(
            //     'JtTag:testName:${GetInstance().getInstanceInfo<HomeLogic>().hashCode}');
            // print('JtTag:Get:${Get.find<HomeLogic>().hashCode}');
            // print('JtTag:testName:${GetInstance().toString()}');
            // print('JtTag:testName:${GetInstance().isRegistered<HomeLogic>()}');
            logic.check();
          },
          child: const Text('查看'),
        ),

        ElevatedButton(
          onPressed: () async {
            print('JtTag:testName:${await Get.delete<HomeLogic>()}');
          },
          child: const Text('手动删除controller'),
        ),

        ElevatedButton(
          onPressed: () {
            print('JtTag:testName:${Get.isRegistered<HomeLogic>()}');
          },
          child: const Text('是否注册'),
        ),

        ElevatedButton(
          onPressed: () {
            logic.name.value += ' +1';
          },
          child: const Text('使用controller'),
        ),
        ElevatedButton(
          onPressed: () {
            Navigator.of(context).popUntil((_) {
              print('JtTag:testName:${_}');
              return true;
            });
          },
          child: const Text('Navigator.pop'),
        )
      ]),
    );
  }
}
